<template>
  <div class="app-container">
    <!-- 完成订单选择 店员 -->
    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
      <el-form :model="formClert">
        <el-form-item label="完成店员" :label-width="80">
          <el-select v-model="formClert.id" placeholder="请选择店员">
            <el-option
              v-for="item in clerkList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancelClerk">取 消</el-button>
        <el-button type="primary" @click="ensureSubmit">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 图表 -->
    <el-row :gutter="40" class="panel-group">
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-money">
            <svg-icon icon-class="peoples" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">总消费金额</div>

            <div class="card-panel-num">{{ countCost }}</div>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-people">
            <svg-icon icon-class="message" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">总成本</div>
            <div class="card-panel-num">{{ countChengben }}</div>
            <!-- <count-to
              :start-val="0"
              :end-val="countCost"
              :duration="3000"
              class="card-panel-num"
            /> -->
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-shopping">
            <svg-icon icon-class="shopping" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">总人工</div>
            <div class="card-panel-num">{{ countMan }}</div>
            <!-- <count-to
              :start-val="0"
              :end-val="number"
              :duration="3600"
              class="card-panel-num"
            /> -->
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-money">
            <svg-icon icon-class="money" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">总利润</div>
            <div class="card-panel-num">
              {{ countCost - countChengben - countMan }}
            </div>
            <!-- <count-to
              :start-val="0"
              :end-val="9280"
              :duration="3200"
              class="card-panel-num"
            /> -->
          </div>
        </div>
      </el-col>
    </el-row>

    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="订单号" prop="id">
        <el-input
          v-model="queryParams.id"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="顾客名称" prop="customer">
        <el-input
          v-model="queryParams.customer"
          placeholder="请输入顾客名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="顾客电话" prop="customerTel">
        <el-input
          v-model="queryParams.customerTel"
          placeholder="请输入顾客电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预约时间" prop="appointTime">
        <el-date-picker
          v-model="queryParams.appointTime"
          type="datetime"
          placeholder="选择日期时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <!-- <el-descriptions class="margin-top" :column="2" border>
      <template slot="extra">
        <div style="500px">
          <el-row :gutter="20">
            <el-col :span="12">
              <div>
                <el-statistic
                  group-separator=","
                  :precision="2"
                  decimal-separator="."
                  :value="countCost"
                  title="总消费金额"
                >
                  <template slot="prefix">
                    <i class="el-icon-s-flag" style="color: red"></i>
                  </template>
                  <template slot="suffix">
                    <i class="el-icon-s-flag" style="color: blue"></i>
                  </template>
                </el-statistic>
              </div>
            </el-col>
            <el-col :span="12">
              <div>
                <el-statistic :value="number" title="已完成订单">
                  <template slot="suffix">
                    <span class="like">
                      <i class="el-icon-star-on" style="color: red"></i>
                    </span>
                  </template>
                </el-statistic>
              </div>
            </el-col>
          </el-row>
        </div>
      </template>
    </el-descriptions> -->

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['product:order:add']"
          >新增</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['product:order:edit']"
          >修改</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['product:order:remove']"
          >删除</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-tabs type="border-card" v-model="activeName" @tab-click="handleClick">
      <el-tab-pane name="first" label="全部订单">
        <el-table
          v-loading="loading"
          border
          :data="orderList"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55" align="center" />
          <!-- <el-table-column label="id" align="center" prop="id" /> -->
          <el-table-column label="预约项目" align="center" width="300">
            <template v-slot="scope">
              <div>
                <img
                  v-show="scope.row.project.filePath"
                  :src="url + scope.row.project.filePath"
                  width="100%"
                />{{ scope.row.projectName }}
              </div>
              <!-- <p>商户名称: {{ scope.row.merchantName }}</p>
          <p>应用名称: {{ scope.row.appName }}</p>
          <p>渠道名称: {{ scope.row.channelCodeName }}</p> -->
            </template>
          </el-table-column>

          <el-table-column label="单价(元)/次" align="center" prop="shopId">
            <template v-slot="scope">
              <p>￥: {{ scope.row.price }}</p>
              <p>一次</p>
            </template>
          </el-table-column>
          <!-- <el-table-column label="品相id" align="center" prop="projectId" /> -->
          <!-- <el-table-column label="品相名称" align="center" prop="projectName" /> -->
          <!-- <el-table-column label="价格" align="center" prop="price" /> -->
          <!-- <el-table-column label="出库价格" align="center" prop="discountPrice" /> -->
          <el-table-column label="订单状态" align="center" prop="status">
          </el-table-column>
          <el-table-column label="需要支付" align="center" prop="needPay">
            <template v-slot="scope">
              <el-tag>￥: {{ scope.row.price }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            label="预约时间"
            align="center"
            prop="appointTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.appointTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="顾客" align="center" prop="customer">
            <template v-slot="scope">
              <div style="text-align: left; margin-left: 20px">
                <p>姓名：{{ scope.row.customer }}</p>
                <p>电话：{{ scope.row.customerTel }}</p>
              </div>
            </template>
          </el-table-column>
          <!-- <el-table-column label="顾客电话" align="center" prop="customerTel" /> -->
          <!-- <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改人" align="center" prop="updateBy" />
      <el-table-column
        label="修改时间"
        align="center"
        prop="updateTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="排序字段" align="center" prop="sort" /> -->
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
            width="400"
          >
            <template slot-scope="scope">
              <el-button
                v-show="scope.row.status === '待商家确认'"
                type="primary"
                plain
                @click="confirm(scope.row)"
                v-hasPermi="['product:order:edit']"
                >确认订单</el-button
              >

              <el-button
                v-show="scope.row.status === '待商家确认'"
                type="danger"
                plain
                @click="cancelOrder(scope.row)"
                v-hasPermi="['product:order:edit']"
                >取消订单</el-button
              >

              <el-button
                v-show="scope.row.status === '预约成功'"
                type="success"
                plain
                @click="finish(scope.row)"
                v-hasPermi="['product:order:edit']"
                >完成订单</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['product:order:edit']"
                >订单详情</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['product:order:remove']"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.page"
          :limit.sync="queryParams.rowsPerPage"
          @pagination="getList"
        />
      </el-tab-pane>
      <el-tab-pane name="second" label="待确认订单">
        <el-table
          v-loading="loading"
          border
          :data="orderList"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55" align="center" />
          <!-- <el-table-column label="id" align="center" prop="id" /> -->
          <el-table-column label="预约项目" align="center" width="300">
            <template v-slot="scope">
              <div>
                <img
                  v-show="scope.row.project.filePath"
                  :src="url + scope.row.project.filePath"
                  width="100%"
                />{{ scope.row.projectName }}
              </div>
              <!-- <p>商户名称: {{ scope.row.merchantName }}</p>
          <p>应用名称: {{ scope.row.appName }}</p>
          <p>渠道名称: {{ scope.row.channelCodeName }}</p> -->
            </template>
          </el-table-column>

          <el-table-column label="单价(元)/次" align="center" prop="shopId">
            <template v-slot="scope">
              <p>￥: {{ scope.row.price }}</p>
              <p>一次</p>
            </template>
          </el-table-column>
          <!-- <el-table-column label="品相id" align="center" prop="projectId" /> -->
          <!-- <el-table-column label="品相名称" align="center" prop="projectName" /> -->
          <!-- <el-table-column label="价格" align="center" prop="price" /> -->
          <!-- <el-table-column label="出库价格" align="center" prop="discountPrice" /> -->
          <el-table-column label="订单状态" align="center" prop="status">
          </el-table-column>
          <el-table-column label="需要支付" align="center" prop="needPay">
            <template v-slot="scope">
              <el-tag>￥: {{ scope.row.price }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            label="预约时间"
            align="center"
            prop="appointTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.appointTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="顾客" align="center" prop="customer">
            <template v-slot="scope">
              <div style="text-align: left; margin-left: 20px">
                <p>姓名：{{ scope.row.customer }}</p>
                <p>电话：{{ scope.row.customerTel }}</p>
              </div>
            </template>
          </el-table-column>
          <!-- <el-table-column label="顾客电话" align="center" prop="customerTel" /> -->
          <!-- <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改人" align="center" prop="updateBy" />
      <el-table-column
        label="修改时间"
        align="center"
        prop="updateTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="排序字段" align="center" prop="sort" /> -->
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
            width="400"
          >
            <template slot-scope="scope">
              <el-button
                v-show="scope.row.status === '待商家确认'"
                type="primary"
                plain
                @click="confirm(scope.row)"
                v-hasPermi="['product:order:edit']"
                >确认订单</el-button
              >

              <el-button
                v-show="scope.row.status === '待商家确认'"
                type="danger"
                plain
                @click="cancelOrder(scope.row)"
                v-hasPermi="['product:order:edit']"
                >取消订单</el-button
              >
              <el-button
                v-show="scope.row.status === '预约成功'"
                type="success"
                plain
                @click="finish(scope.row)"
                v-hasPermi="['product:order:edit']"
                >完成订单</el-button
              >

              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['product:order:edit']"
                >订单详情</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['product:order:remove']"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.page"
          :limit.sync="queryParams.rowsPerPage"
          @pagination="getList"
        />
      </el-tab-pane>
      <el-tab-pane name="third" label="已接单">
        <el-table
          v-loading="loading"
          border
          :data="orderList"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55" align="center" />
          <!-- <el-table-column label="id" align="center" prop="id" /> -->
          <el-table-column label="预约项目" align="center" width="300">
            <template v-slot="scope">
              <div>
                <img
                  v-show="scope.row.project.filePath"
                  :src="url + scope.row.project.filePath"
                  width="100%"
                />{{ scope.row.projectName }}
              </div>
              <!-- <p>商户名称: {{ scope.row.merchantName }}</p>
          <p>应用名称: {{ scope.row.appName }}</p>
          <p>渠道名称: {{ scope.row.channelCodeName }}</p> -->
            </template>
          </el-table-column>

          <el-table-column label="单价(元)/次" align="center" prop="shopId">
            <template v-slot="scope">
              <p>￥: {{ scope.row.price }}</p>
              <p>一次</p>
            </template>
          </el-table-column>
          <!-- <el-table-column label="品相id" align="center" prop="projectId" /> -->
          <!-- <el-table-column label="品相名称" align="center" prop="projectName" /> -->
          <!-- <el-table-column label="价格" align="center" prop="price" /> -->
          <!-- <el-table-column label="出库价格" align="center" prop="discountPrice" /> -->
          <el-table-column label="订单状态" align="center" prop="status">
          </el-table-column>
          <el-table-column label="需要支付" align="center" prop="needPay">
            <template v-slot="scope">
              <el-tag>￥: {{ scope.row.price }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            label="预约时间"
            align="center"
            prop="appointTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.appointTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="顾客" align="center" prop="customer">
            <template v-slot="scope">
              <div style="text-align: left; margin-left: 20px">
                <p>姓名：{{ scope.row.customer }}</p>
                <p>电话：{{ scope.row.customerTel }}</p>
              </div>
            </template>
          </el-table-column>
          <!-- <el-table-column label="顾客电话" align="center" prop="customerTel" /> -->
          <!-- <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改人" align="center" prop="updateBy" />
      <el-table-column
        label="修改时间"
        align="center"
        prop="updateTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="排序字段" align="center" prop="sort" /> -->
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
            width="400"
          >
            <template slot-scope="scope">
              <el-button
                v-show="scope.row.status === '待商家确认'"
                type="primary"
                plain
                @click="confirm(scope.row)"
                v-hasPermi="['product:order:edit']"
                >确认订单</el-button
              >

              <el-button
                v-show="scope.row.status === '待商家确认'"
                type="danger"
                plain
                @click="cancelOrder(scope.row)"
                v-hasPermi="['product:order:edit']"
                >取消订单</el-button
              >

              <el-button
                v-show="scope.row.status === '预约成功'"
                type="success"
                plain
                @click="finish(scope.row)"
                v-hasPermi="['product:order:edit']"
                >完成订单</el-button
              >

              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['product:order:edit']"
                >订单详情</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['product:order:remove']"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.page"
          :limit.sync="queryParams.rowsPerPage"
          @pagination="getList"
        />
      </el-tab-pane>
      <el-tab-pane name="fourth" label="已完成订单">
        <el-table
          v-loading="loading"
          border
          :data="orderList"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55" align="center" />
          <!-- <el-table-column label="id" align="center" prop="id" /> -->
          <el-table-column label="预约项目" align="center" width="300">
            <template v-slot="scope">
              <div>
                <img
                  v-show="scope.row.project.filePath"
                  :src="url + scope.row.project.filePath"
                  width="100%"
                />{{ scope.row.projectName }}
              </div>
              <!-- <p>商户名称: {{ scope.row.merchantName }}</p>
          <p>应用名称: {{ scope.row.appName }}</p>
          <p>渠道名称: {{ scope.row.channelCodeName }}</p> -->
            </template>
          </el-table-column>

          <el-table-column label="单价(元)/次" align="center" prop="shopId">
            <template v-slot="scope">
              <p>￥: {{ scope.row.price }}</p>
              <p>一次</p>
            </template>
          </el-table-column>
          <!-- <el-table-column label="品相id" align="center" prop="projectId" /> -->
          <!-- <el-table-column label="品相名称" align="center" prop="projectName" /> -->
          <!-- <el-table-column label="价格" align="center" prop="price" /> -->
          <!-- <el-table-column label="出库价格" align="center" prop="discountPrice" /> -->
          <el-table-column label="订单状态" align="center" prop="status">
          </el-table-column>
          <el-table-column label="需要支付" align="center" prop="needPay">
            <template v-slot="scope">
              <el-tag>￥: {{ scope.row.price }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            label="预约时间"
            align="center"
            prop="appointTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.appointTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="顾客" align="center" prop="customer">
            <template v-slot="scope">
              <div style="text-align: left; margin-left: 20px">
                <p>姓名：{{ scope.row.customer }}</p>
                <p>电话：{{ scope.row.customerTel }}</p>
              </div>
            </template>
          </el-table-column>
          <!-- <el-table-column label="顾客电话" align="center" prop="customerTel" /> -->
          <!-- <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改人" align="center" prop="updateBy" />
      <el-table-column
        label="修改时间"
        align="center"
        prop="updateTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="排序字段" align="center" prop="sort" /> -->
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
            width="400"
          >
            <template slot-scope="scope">
              <el-button
                v-show="scope.row.status === '待商家确认'"
                type="primary"
                plain
                @click="confirm(scope.row)"
                v-hasPermi="['product:order:edit']"
                >确认订单</el-button
              >

              <el-button
                v-show="scope.row.status === '待商家确认'"
                type="danger"
                plain
                @click="cancelOrder(scope.row)"
                v-hasPermi="['product:order:edit']"
                >取消订单</el-button
              >

              <el-button
                v-show="scope.row.status === '预约成功'"
                type="success"
                plain
                @click="finish(scope.row)"
                v-hasPermi="['product:order:edit']"
                >完成订单</el-button
              >

              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['product:order:edit']"
                >订单详情</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['product:order:remove']"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.page"
          :limit.sync="queryParams.rowsPerPage"
          @pagination="getList"
      /></el-tab-pane>
      <el-tab-pane name="five" label="已取消">
        <el-table
          v-loading="loading"
          border
          :data="orderList"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55" align="center" />
          <!-- <el-table-column label="id" align="center" prop="id" /> -->
          <el-table-column label="预约项目" align="center" width="300">
            <template v-slot="scope">
              <div>
                <img
                  v-show="scope.row.project.filePath"
                  :src="url + scope.row.project.filePath"
                  width="100%"
                />{{ scope.row.projectName }}
              </div>
              <!-- <p>商户名称: {{ scope.row.merchantName }}</p>
          <p>应用名称: {{ scope.row.appName }}</p>
          <p>渠道名称: {{ scope.row.channelCodeName }}</p> -->
            </template>
          </el-table-column>

          <el-table-column label="单价(元)/次" align="center" prop="shopId">
            <template v-slot="scope">
              <p>￥: {{ scope.row.price }}</p>
              <p>一次</p>
            </template>
          </el-table-column>
          <!-- <el-table-column label="品相id" align="center" prop="projectId" /> -->
          <!-- <el-table-column label="品相名称" align="center" prop="projectName" /> -->
          <!-- <el-table-column label="价格" align="center" prop="price" /> -->
          <!-- <el-table-column label="出库价格" align="center" prop="discountPrice" /> -->
          <el-table-column label="订单状态" align="center" prop="status">
          </el-table-column>
          <el-table-column label="需要支付" align="center" prop="needPay">
            <template v-slot="scope">
              <el-tag>￥: {{ scope.row.price }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            label="预约时间"
            align="center"
            prop="appointTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.appointTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="顾客" align="center" prop="customer">
            <template v-slot="scope">
              <div style="text-align: left; margin-left: 20px">
                <p>姓名：{{ scope.row.customer }}</p>
                <p>电话：{{ scope.row.customerTel }}</p>
              </div>
            </template>
          </el-table-column>
          <!-- <el-table-column label="顾客电话" align="center" prop="customerTel" /> -->
          <!-- <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改人" align="center" prop="updateBy" />
      <el-table-column
        label="修改时间"
        align="center"
        prop="updateTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="排序字段" align="center" prop="sort" /> -->
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
            width="400"
          >
            <template slot-scope="scope">
              <el-button
                v-show="scope.row.status === '待商家确认'"
                type="primary"
                plain
                @click="confirm(scope.row)"
                v-hasPermi="['product:order:edit']"
                >确认订单</el-button
              >

              <el-button
                v-show="scope.row.status === '待商家确认'"
                type="danger"
                plain
                @click="cancelOrder(scope.row)"
                v-hasPermi="['product:order:edit']"
                >取消订单</el-button
              >

              <el-button
                v-show="scope.row.status === '预约成功'"
                type="success"
                plain
                @click="finish(scope.row)"
                v-hasPermi="['product:order:edit']"
                >完成订单</el-button
              >

              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['product:order:edit']"
                >订单详情</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['product:order:remove']"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.page"
          :limit.sync="queryParams.rowsPerPage"
          @pagination="getList"
      /></el-tab-pane>
    </el-tabs>

    <!-- 订单详情 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1200px"
      append-to-body
    >
      <el-descriptions title="订单信息">
        <el-descriptions-item label="订单号">{{
          form.id
        }}</el-descriptions-item>
        <el-descriptions-item label="订单来源"></el-descriptions-item>
        <el-descriptions-item label="客户名称">{{
          form.customer
        }}</el-descriptions-item>
        <el-descriptions-item label="客户电话">{{
          form.customerTel
        }}</el-descriptions-item>
        <el-descriptions-item label="预约时间">{{
          form.appointTime
        }}</el-descriptions-item>
        <el-descriptions-item label="确定时间">
          <el-tag v-show="form.confirmTime" size="small"
            >{{ form.confirmTime }}分钟</el-tag
          >
        </el-descriptions-item>
        <el-descriptions-item label="人工成本">
          <el-tag v-show="form.manHourCost" size="small"
            >￥:{{ form.manHourCost }}</el-tag
          >
        </el-descriptions-item>
        <el-descriptions-item label="需要支付">
          <el-tag size="small">￥：{{ form.needPay }}</el-tag>
        </el-descriptions-item>
        <!-- <el-descriptions-item label="联系地址"
          >江苏省苏州市吴中区吴中大道 1188 号</el-descriptions-item > -->
      </el-descriptions>
      <el-divider></el-divider>
      <el-descriptions title="订单状态">
        <el-descriptions-item label="订单状态">{{
          form.status
        }}</el-descriptions-item>
        <!-- <el-descriptions-item label="联系地址"
          >江苏省苏州市吴中区吴中大道 1188 号</el-descriptions-item > -->
      </el-descriptions>
      <el-divider></el-divider>
      <el-descriptions title="品相信息">
        <el-descriptions-item label="品相名称">{{
          formProject.name
        }}</el-descriptions-item>
        <el-descriptions-item label="品相描述">{{
          formProject.description
        }}</el-descriptions-item>
        <el-descriptions-item label="所需时间"
          >{{ formProject.needTime }}分钟</el-descriptions-item
        >
        <!-- <el-descriptions-item label="是否开启拼团">
          <el-tag size="small">{{ formProject.ptStatus }}</el-tag>
        </el-descriptions-item> -->
        <el-descriptions-item label="商品成本">
          <el-tag size="small">￥：{{ form.goodsCost }}</el-tag>
        </el-descriptions-item>
      </el-descriptions>
      <el-table :data="formProject.goods" border style="width: 75%">
        <el-table-column prop="id" label="商品ID" width="180">
        </el-table-column>
        <el-table-column prop="name" label="商品名称" width="180">
        </el-table-column>
        <el-table-column prop="sum" label="所需数量(件)">
          <template v-slot="scope">
            <p>{{ scope.row.sum }}</p>
          </template>
        </el-table-column>
      </el-table>

      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="submitForm">确 定</el-button> -->
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
    <!-- 新增订单 -->
    <el-dialog
      :title="title"
      :visible.sync="opennew"
      width="500px"
      append-to-body
    >
      <el-form ref="formNew" :model="formNew" :rules="rules" label-width="80px">
        <el-form-item label="顾客名称" prop="customer">
          <el-select
            v-model="formNew.customer"
            filterable
            placeholder="请选择顾客名称(可搜索)"
            @change="selectChange"
          >
            <el-option
              v-for="item in customerList"
              :key="item.id"
              :label="item.name"
              :value="item.name"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="顾客电话" prop="customerTel">
          <el-input
            style="width: 220px"
            disabled
            v-model="formNew.customerTel"
            placeholder="请输入顾客电话"
          />
        </el-form-item>
        <el-form-item label="项目" prop="projectId">
          <el-select
            v-model="formNew.projectId"
            filterable
            placeholder="请选择项目"
          >
            <el-option
              v-for="item in itemList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="预约时间" prop="appointTime">
          <el-date-picker
            v-model="formNew.appoindTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择预约时间"
          >
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel2">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listOrder,
  getOrder,
  delOrder,
  addOrder,
  updateOrder,
  confirmOrder,
  finishOrder,
  delOrders,
  placeOrder,
} from "@/api/product/order";
import { getItemById, listItem } from "@/api/product/item";
import { listCustomer } from "@/api/product/customer";
import url from "@/api/product/url";
import CountTo from "vue-count-to";
import { listClerk } from "@/api/product/clerk";
import { getShop } from "@/api/product/item";
export default {
  name: "Order",
  components: {
    CountTo,
  },
  data() {
    return {
      nowOrderId: "",
      dialogVisible: false,
      formClert: {},
      clerkList: [],
      //品相列表
      itemList: [],
      // 顾客列表
      customerList: [],
      activeName: "first",
      url: url.httpUrl,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      orderList: [],

      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      opennew: false,
      // 查询参数
      queryParams: {
        page: 1,
        rowsPerPage: 10,
        shopId: null,
        projectId: null,
        projectName: null,
        price: null,
        status: null,
        discountPrice: null,
        needPay: null,
        appointTime: null,
        customer: null,
        customerTel: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        sort: null,
      },
      // 表单参数
      shopInfo: {},
      form: {},
      formNew: {},
      formProject: {},
      orders: [],
      // 表单校验
      rules: {
        customer: [
          { required: true, message: "店铺名称不能为空", trigger: "blur" },
        ],
        // password: [
        //   { required: true, message: "用户密码不能为空", trigger: "blur" },
        //   { min: 5, max: 20, message: '用户密码长度必须介于 5 和 20 之间', trigger: 'blur' }
        // ],
        appoindTime: [
          { required: true, message: "时间不能为空", trigger: "blur" },
        ],
        //  endTime:[{
        //   type:"date",required:true,message:"请选择日期",trigger:"change"
        // }],
        // email: [
        //   {
        //     type: "email",
        //     message: "请输入正确的邮箱地址",
        //     trigger: ["blur", "change"]
        //   }
        // ],
        // address: [{ required: true, message: "地址不能为空", trigger: "blur" }],
        customerTel: [
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur",
          },
        ],
        //  introduce: [
        //   { required: true, message: "自我介绍不能为空", trigger: "blur" }
        // ],
      },
    };
  },
  created() {
    this.getList();
    this.getLoginShop();
  },
  computed: {
    //属性名字（计算属性名称）
    //属性的值（计算属性处理函数）
    countCost() {
      // 对依赖的数据进行处理，且进行return
      let cout = this.orders.filter((item) => {
        return item.status === "已完成";
      });
      return cout.reduce((pre, current) => pre + parseFloat(current.price), 0);
    },
    number() {
      return this.orders.filter((item) => {
        return item.status === "已完成";
      }).length;
    },
    // 总利润
    lirun() {
      let cout = this.orders.filter((item) => {
        return item.status === "已完成";
      });
      return cout.reduce(
        (pre, current) =>
          pre +
          (parseFloat(current.needPay) -
            parseFloat(current.manHourCost) -
            parseFloat(current.goodsCost)),
        0
      );
    },

    // 总成本
    countChengben() {
      // 对依赖的数据进行处理，且进行return
      let cout = this.orders.filter((item) => {
        return item.status === "已完成";
      });
      return cout.reduce(
        (pre, current) => pre + parseFloat(current.goodsCost),
        0
      );
    },

    // 总人工
    countMan() {
      // 对依赖的数据进行处理，且进行return
      let cout = this.orders.filter((item) => {
        return item.status === "已完成";
      });
      return cout.reduce(
        (pre, current) => pre + parseFloat(current.manHourCost),
        0
      );
    },
  },
  methods: {
    //  顾客选择框选中
    selectChange(e) {
      const customer = this.customerList.filter((row) => row.name == e)[0];
      console.log(customer);
      this.formNew.customerTel = customer.tel;
    },

    handleClick(tab, event) {
      if (tab.name == "second") {
        this.queryParams.status = "待商家确认";
      } else if (tab.name == "third") {
        this.queryParams.status = "预约成功";
      } else if (tab.name == "fourth") {
        this.queryParams.status = "已完成";
      } else if (tab.name == "five") {
        this.queryParams.status = "已取消";
      } else {
        this.queryParams.status = null;
      }
      this.getList();
    },
    /**完成订单 */
    finish(row) {
      let params = {
        page: 1,
        rowsPerPage: 999,
        status: "在职",
      };
      this.nowOrderId = row.id;
      listClerk(params).then((response) => {
        this.clerkList = response.data.list;
      });
      this.dialogVisible = true;
    },

    ensureSubmit() {
      let data = {
        clerkId: this.formClert.id,
        orderId: this.nowOrderId,
      };
      finishOrder(data).then((res) => {
        if (res.code === 200) {
          this.$modal.msgSuccess("订单已完成！");
          this.getList();
          this.dialogVisible = false;
          this.nowOrderId = "";
        }
      });
    },

    cancelClerk() {
      this.dialogVisible = false;
      this.resetClerk();
    },
    /**确定订单 */
    confirm(row) {
      const data = {
        orderId: row.id,
        result: "yes",
      };
      confirmOrder(data).then((res) => {
        if (res.code === 200) {
          this.$modal.msgSuccess("确定订单成功！");
          this.getList();
        }
      });
    },
    /**取消订单 */
    cancelOrder(row) {
      const data = {
        orderId: row.id,
        result: "no",
      };
      confirmOrder(data).then((res) => {
        if (res.code === 200) {
          this.$modal.msgSuccess("已取消订单！");
          this.getList();
        }
      });
    },
    /** 查询订单列表 */
    getList() {
      this.loading = true;
      listOrder(this.queryParams).then((response) => {
        this.orderList = response.data.list;
        this.total = response.data.totalCount;
        this.loading = false;
      });
      this.getOrderList();
    },

    getOrderList() {
      listOrder().then((response) => {
        this.orders = JSON.parse(JSON.stringify(response.data.list));
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancel2() {
      this.opennew = false;
      this.reset2();
    },

    resetClerk() {
      this.formClert = {
        id: null,
      };
      this.resetForm("formClert");
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        shopId: null,
        projectId: null,
        projectName: null,
        price: null,
        discountPrice: null,
        needPay: null,
        appointTime: null,
        customer: null,
        customerTel: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        sort: null,
        project: {},
      };
      this.formProject = {};
      this.resetForm("form");
    },
    reset() {
      this.formNew = {
        projectId: null,
        appoindTime: null,
        customer: null,
        customerTel: null,
      };
      this.resetForm("formNew");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },

    // 获取登陆人店铺
    getLoginShop() {
      getShop().then((res) => {
        this.shopInfo = res.data;
      });
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      let data = {
        page: 1,
        rowsPerPage: 9999,
        shopId: this.shopInfo.id,
      };
      listCustomer(data).then((res) => {
        this.customerList = res.data.list;
      });

      listItem(data).then((res) => {
        this.itemList = res.data.list;
      });
      this.opennew = true;
      this.title = "添加订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getOrder(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "订单详情";
        getItemById(response.data.projectId).then((res) => {
          if (res.code === 200) {
            this.formProject = res.data;
          }
        });
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["formNew"].validate((valid) => {
        if (valid) {
          placeOrder(this.formNew).then((response) => {
            this.$modal.msgSuccess("新增订单成功");
            this.opennew = false;
            this.getList();
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      if (row.id) {
        this.$modal
          .confirm('是否确认删除订单编号为"' + id + '"的数据项？')
          .then(function () {
            return delOrder(id);
          })
          .then(() => {
            this.getList();
            this.$modal.msgSuccess("删除成功");
          })
          .catch(() => {});
      } else {
        const ids = this.ids.join(",");
        this.$modal
          .confirm('是否确认删除订单编号为"' + ids + '"的数据项？')
          .then(function () {
            return delOrders(ids);
          })
          .then(() => {
            this.getList();
            this.$modal.msgSuccess("删除成功");
          })
          .catch(() => {});
      }
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "product/order/export",
        {
          ...this.queryParams,
        },
        `order_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>

<style lang="scss" scoped>
.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3;
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3;
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

@media (max-width: 550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
.text {
  font-size: 14px;
}

.item {
  padding: 18px 0;
}

.box-card {
  width: 480px;
}
</style>